import React, { useEffect, useState } from 'react';
import { getArticleList } from "../../store/counterSlice";
import { useSelector, useDispatch } from 'react-redux'
import instance from "../../apis/request";
import { Space, Table, Tag } from 'antd';
import Search from "../../computed/Search";
function Article() {
     const {articleData,count} = useSelector(state => state.counter)
  const dispatch = useDispatch()
  const [data,setData]=useState({
    page:1,//页码  必传
pageSize:6,//每页显示条数 必传
keyword:null,//搜索标题
tag:null//搜索标签

  })
  const [fy,setFy]=useState({
    current:1,
    pageSize:6,
    total:0
  })
  const aa=async()=>{
    const res=await instance.get('/article/list',{
        params:data
    }).then(res=>{
        console.log(res);
        
        dispatch(getArticleList(res))
        setFy({
            ...fy,
            total:res.count
        })
    })
  }
  useEffect(()=>{
    aa()
  },[data,dispatch])
  const dd=(diss)=>{
    setData({
        page:diss.current,
        pageSize:diss.pageSize
    })
    setFy({
        current:diss.current,
        pageSize:diss.pageSize,
        total:diss.count
    })
  }
  const columns = [
  {
    title: '用户名',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '性别',
    dataIndex: 'content',
    key: 'content',
  },
  {
    title: '年龄',
    dataIndex: 'id',
    key: 'id',
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    key: 'createdAt',
  },
  {
    title: '操作',
    key: 'action',
    render: (_, record) => (
      <Space size="middle">
        <a>编辑</a>
        <a>删除</a>
      </Space>
    ),
  },
];

const onchangesou=(k)=>{
    setData({
        ...data,
        keyword:k.keyword
    })
}
    return (
        <div>
            <Search kkk={onchangesou} />
            <Table dataSource={articleData} columns={columns} pagination={fy} onChange={dd} />
        </div>
    );
}

export default Article;